GBML manual / Constants

EASE_ELASTIC_IN

Wobbles with bigger and bigger swings, like a spring being wound up, and then arrives. The number swings behind the start by over a third of the distance, so it leaves the range.

Syntax

EASE_ELASTIC_IN: constant

Description

The "elastic in" curve for tween and tween_to: a spring being wound up. It wobbles round the start with bigger and bigger swings and then snaps to the end. After a quarter of the time it has hardly moved (-0.01), after half it is at -0.02, and after three quarters at 0.09.

The number leaves the range

Most curves keep the number between from and to. This one does not. The swings go behind from by up to about 37% of the distance: a number tweened from 100 to 200 swings to about 113 and then down to about 63, each swing bigger than the one before, and then flies to 200.

When the number is a position, that is the whole point: a wound-up spring, a jolt before a launch. When the number has to stay in a range it is a problem, and a bigger one than back's, because the swings are bigger:

tween_to(hp, 100, 90, EASE_ELASTIC_IN);   // hp swings well below its start: don't do this to a number with limits

For a number that must stay between its two ends, use a sine or quad curve, or a bounce, which never goes outside them. It does arrive exactly: after the end the number is exactly to, every frame.

A real capture, 27 frames played in a loop - three small graphs, one above the other, labeled in, out and in out. In each one a ball moves steadily to the right while its height on the screen is the number being tweened: a dim dashed line at the top is where the number starts, a green dashed line below it is where it ends, and a trail of dots shows where the ball has been. In the out row the ball shoots down past the green line by a long way and then wobbles up and down round it with smaller and smaller swings until it rests on it, like a spring let go. The in row is the same wobble the other way round: swings round the dim line that grow bigger, and then a drop onto the green line. The in out row winds up round the dim line, crosses the middle, and wobbles round the green line. The first frame, which is all a viewer that cannot animate shows, is the finished picture: every dot, drawing the whole of each curve.A real capture, 27 frames played in a loop - three small graphs, one above the other, labeled in, out and in out. In each one a ball moves steadily to the right while its height on the screen is the number being tweened: a dim dashed line at the top is where the number starts, a green dashed line below it is where it ends, and a trail of dots shows where the ball has been. In the out row the ball shoots down past the green line by a long way and then wobbles up and down round it with smaller and smaller swings until it rests on it, like a spring let go. The in row is the same wobble the other way round: swings round the dim line that grow bigger, and then a drop onto the green line. The in out row winds up round the dim line, crosses the middle, and wobbles round the green line. The first frame, which is all a viewer that cannot animate shows, is the finished picture: every dot, drawing the whole of each curve.
A real capture, 27 frames played in a loop - three small graphs, one above the other, labeled in, out and in out. In each one a ball moves steadily to the right while its height on the screen is the number being tweened: a dim dashed line at the top is where the number starts, a green dashed line below it is where it ends, and a trail of dots shows where the ball has been. In the out row the ball shoots down past the green line by a long way and then wobbles up and down round it with smaller and smaller swings until it rests on it, like a spring let go. The in row is the same wobble the other way round: swings round the dim line that grow bigger, and then a drop onto the green line. The in out row winds up round the dim line, crosses the middle, and wobbles round the green line. The first frame, which is all a viewer that cannot animate shows, is the finished picture: every dot, drawing the whole of each curve.

The same tween three ways, one row for each of EASE_ELASTIC_IN, EASE_ELASTIC_OUT and EASE_ELASTIC_IN_OUT. The ball's height is the number (like tween_to(y, ...) moving something down), and it drifts right at a steady speed only so that the shape can be seen. The dim line is where the number starts and the green line is where it ends: the ball goes a long way past the green line (and, for the in, behind the dim one). Real pictures from a Game Boy Advance ROM, 4 frames apart, played at the speed of the console. A viewer that does not animate shows the first picture, the finished one.

Example

tween_to(x, x + 100, 70, EASE_ELASTIC_IN);

The walker barely moves at first, then wobbles back and forth round where it started (as far as about 37 pixels behind it at the biggest swing) and shoots off 100 pixels to the right, arriving exactly there.

Uncommon on its own: it is usually the out curve people want. It works for a build-up before something happens, such as a spring-loaded door that shakes before it flies open.

Cost

An elastic curve does more maths than the others: a sine and a fading factor on every frame it is read. That is fine for the handful of tweens a screen has at once, and a game that uses none of the elastic curves is not made any slower by them.

See also: tweentween_totween_from_to